//
//  GXMainViewController.swift
//  BallGame
//
//  Created by GuangXiao on 16/1/24.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit
import LocalAuthentication

class GXMainViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    private func setupUI(){
        view.backgroundColor = UIColor.whiteColor()
        view.addSubview(imageView)
        view.addSubview(gameOneButton)
        view.addSubview(gameTwoButton)
        imageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view.snp_centerX)
            make.centerY.equalTo(view.snp_centerY).offset(-ScreenHeight * 0.1)
        }
        gameOneButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(imageView.snp_centerX)
            make.top.equalTo(imageView.snp_bottom).offset(30)
        }
        
        gameTwoButton.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(gameOneButton.snp_centerX)
            make.top.equalTo(gameOneButton.snp_bottom).offset(30)
        }
    }
    
    @objc private func buttonClick(){
        
        let gameVc = GXGameViewController()
        navigationController?.pushViewController(gameVc, animated: true)
    }
    
    @objc private func buttonTwoClick(){
//        //1.指纹识别上下文
//        let context = LAContext()
////        print(NSThread.currentThread())
//
//        //2.判断指纹识别是否可用
//        if context.canEvaluatePolicy(.DeviceOwnerAuthentication, error: nil){
//            context.evaluatePolicy(.DeviceOwnerAuthentication, localizedReason: "指纹识别更安全", reply: { (_, error) -> Void in
//                
//                if error != nil {
//                    print("指纹识别错误")
//                }else {
//                    //将UI 放到主线程中
//                    dispatch_async(dispatch_get_main_queue(), { () -> Void in
//                        print("指纹识别成功")
////                        print(NSThread.currentThread())
//                        let gameTwoVc = GXGameTwoViewController()
//                        self.navigationController?.pushViewController(gameTwoVc, animated: true)
//                    })
//
//                }
//            })
//        }

        let gameTwoVc = GXOtherTableViewController()
        self.navigationController?.pushViewController(gameTwoVc, animated: true)
        
    }
    
    //懒加载控件
    private lazy var imageView : UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "ball"))
        
        return imageView
    }()
    
    private lazy var gameOneButton : UIButton = {
        let button = UIButton()
        button.addTarget(self, action: "buttonClick", forControlEvents:.TouchUpInside)
        button.setTitle("游戏", forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: .Highlighted)
        return button
    }()
    
    private lazy var gameTwoButton : UIButton = {
        let button = UIButton()
        button.addTarget(self, action: "buttonTwoClick", forControlEvents:.TouchUpInside)
        button.setTitle("其他", forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button"), forState: .Normal)
        button.setBackgroundImage(UIImage(named: "new_feature_finish_button_highlighted"), forState: .Highlighted)
        return button
    }()

}
